library bugzilla;

include <core.vhs>
include <netutil.vhs>

import core::*;
import core::Pattern::*;
import core::Logging::*;
import core::JobEngine::*;
import netutil::*;

const BUGZILLA_DETAIL = 100;

pattern Bugzilla($outfunc, $outfunc_arg = null, $mfsa) {
	
	var bugId = getXMLtext('bug_id');
	var reportedDate = getXMLtext('creation_ts');
	if (reportedDate.length() > 10)
		reportedDate = reportedDate.substring(0, 10);
	outfunc?(struct { Type = BUGZILLA_DETAIL, ID = bugId, DisclosureDate = reportedDate, MFSA = mfsa}, outfunc_arg)
}

function getXMLtext(tag, text = this.LocalInput) {
	var patText = String.format('<%s>(.+?)</%s>', [tag, tag]);
	var m = match(text, patText);
	return if (m.find()) m.group(1) else "";
}